from rest_framework import serializers

from note.serializers import NoteSerializer, UserSerializer
from .models import HistoryRecord

class HistoryRecordSerializer(serializers.ModelSerializer):
    note_title = serializers.ReadOnlyField(source='note.title')  # 读取笔记的标题
    note = NoteSerializer(read_only=True)
    user = UserSerializer(read_only=True)  # 嵌套用户序列化器

    class Meta:
        model = HistoryRecord
        fields = ['id', 'user', 'note', 'note_title', 'action', 'created_at']
